package top.saplf.sileny.ext

import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.animation.ValueAnimator
import android.support.design.widget.TabLayout

/**
 * @author saplf
 */
typealias TabSelectedAction = (TabLayout.Tab) -> Unit
inline fun TabLayout.addOnTabSelectedListener(
        crossinline tabReselected: TabSelectedAction,
        crossinline tabSelectedAction: TabSelectedAction) {
    addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
        override fun onTabReselected(tab: TabLayout.Tab) {
            tabReselected(tab)
        }

        override fun onTabUnselected(tab: TabLayout.Tab) {

        }

        override fun onTabSelected(tab: TabLayout.Tab) {
            tabSelectedAction(tab)
        }

    })
}

inline fun ValueAnimator.addListenerStopListener(crossinline action: (animation: Animator) -> Unit) {
    addListener(object : AnimatorListenerAdapter() {
        override fun onAnimationEnd(animation: Animator) {
            action(animation)
        }
    })
}
